<template>
  <div class="detailNavBar">
    <nav-bar>
      <template #left>
        <div class="back" @click="$router.back()">
          <img src="@/assets/img/common/back.svg" alt="" />
        </div>
      </template>
      <template #center>
        <div class="titles">
          <div
            v-for="(item, index) in titles"
            :class="{ active: index === currentIndex }"
            :key="item"
            @click="titleClick(index)"
          >
            {{ item }}
          </div>
        </div>
      </template>
      <template #right>
        <div class="chart" @click="$router.go(0)">
          <img src="@/assets/img/detail/cart.png" alt="" />
        </div>
      </template>
    </nav-bar>
  </div>
</template>

<script>
import NavBar from "@/components/common/navbar/NavBar.vue";

export default {
  name: "DetailNavBar",
  components: {
    NavBar,
  },
  data() {
    return {
      titles: ["商品", "评论", "参数", "推荐"],
      currentIndex: 0,
    };
  },
  methods: {
    titleClick(index) {
      this.currentIndex = index;
      this.$emit("titleClick", index);
    },
  },
};
</script>

<style scoped>
.titles {
  display: flex;
}
.titles div {
  flex: 1;
}
.active {
  color: var(--color-high-text);
}
.back {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.back img {
  width: 40%;
}
.chart {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chart img {
  width: 50%;
}
</style>
